package com.yutel.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yutel.system.dao.IExtPanelDao;
import com.yutel.system.repository.ExtComm;
import com.yutel.system.repository.ExtPanel;
import com.yutel.system.service.IExtPanelService;

public class ExtPanelService implements IExtPanelService {

	public ExtPanel panel(ExtPanel panel) {
		ExtPanel p=extPanelDao.view(panel.getId());
		return extPanelDao.panel(p);
	}
	public Integer rootId(ExtPanel panel) {
		while(true) {
			if(panel.getPid()==null || panel.getPid()<1){
				return panel.getId();
			} else {
				panel=extPanelDao.view(panel.getPid());
			}
		}
	}
	public List<ExtPanel> list(ExtPanel panel) {
		return extPanelDao.list(panel);
	}
	public void add(ExtPanel panel) {
		extPanelDao.add(panel);
	}

	public void del(ExtPanel panel) {
		extPanelDao.del(panel);
	}

	public void edit(ExtPanel panel) {
		extPanelDao.edit(panel);
	}
	
	public ExtPanel view(ExtPanel panel) {
		return extPanelDao.view(panel.getId());
	}
	
	public Map<String,String> panelCols(ExtPanel panel) {
		List<ExtComm> list=extPanelDao.commByPage(panel);
		Map<String,String> map=new HashMap<String,String>();
		map.put("id", "id");
		for(ExtComm ec:list){
			if("colName".equalsIgnoreCase(ec.getType())){
				map.put(ec.getColName(), ec.getColName());
			}
		}
		return map;
	}

	public List<ExtComm> commByPage(ExtPanel panel) {
		return extPanelDao.commByPage(panel);
	}
	public void addComm(ExtComm comm) {
		extPanelDao.addComm(comm);
	}

	public void delComm(String commIds) {
		extPanelDao.delComm(commIds);
	}

	public void editComm(ExtComm comm) {
		extPanelDao.editComm(comm);
	}
	public ExtComm viewComm(ExtComm comm) {
		return extPanelDao.viewComm(comm);
	}
	
	private IExtPanelDao extPanelDao;
	public IExtPanelDao getExtPanelDao() {
		return extPanelDao;
	}
	public void setExtPanelDao(IExtPanelDao extPanelDao) {
		this.extPanelDao = extPanelDao;
	}
}
